var userInf;
apiready = function() {
	$api.getUserInf(function(user) {
		// $("#realName").val(user.ownerName);
		// $("#myemail").val(user.email);
		// $("#myphone").val(uer.account);
		$('#account').text(user.account);
		userInf = user;
		$api.do_post('/api/property/owner/info/query', {
			body: $api.jsonToStr({
				phone: user.tel
			})
		}, function(result) {
			if (result.code == "0") {
				
				var template = $("#fcListT").html();
				$.each(result.ownerInfos, function(i, item) {
					residential
					var content = template.replace(/\{\{index\}\}/g, i)
						.replace(/\{\{residential\}\}/g, item.residential)
						.replace(/\{\{unitName\}\}/g, item.unitName)
						.replace(/\{\{roomNumber\}\}/g, item.roomNumber);
					$("#fcrq").append(content);
					//console.log(content)
					$("#item_" + i).attr("data-item", item)

				})
				$("#fcResult").show();
				if (result.ownerInfos && result.ownerInfos.length > 0) {
					var firstRow = result.ownerInfos[0];

					$("#code").attr('value', result.msgCode);
					$("#residential").attr('value', firstRow.residential);
					$("#unitName").attr('value', firstRow.unitName);
					$("#roomNumber").attr('value', firstRow.roomNumber);
					$("#IDCard").attr('value', firstRow.IDCard);
					$("#name").attr('value', firstRow.name);
					$("#zycode").attr('value', firstRow.code);

				}
			} else {
				$("#errmsg").text(JSON.stringify(result));
				$('#my-alert').modal({
					relatedTarget: this,
				});
				return;
			}
		})
	});
}

$("#sub_btn").click(function() {
	var phone = $("#phone").val();
	var openId = $("#openId").val();
	var data = {
		"openId": $("#openId").val(),
		"IDCard": $("#IDCard").val(),
		"nickName": $("#nickName").val(),
		"realName": $("#realName").val(),
		"recman": $("#recman").val(),
		"mobile": $("#myphone").val(),
	};

	var param = {	
			account: userInf.account,
			mobile: userInf.account,
			zycode: ownerInfo.code,
			ownerName: ownerInfo.name,
			ownerMobile: pNum,
			residential: ownerInfo.residential,
			unitName: ownerInfo.unitName,
			roomNumber: ownerInfo.roomNumber,
			vCode: $("#msgCode").val(),
		}
	$.post('/wx/property/commuser/save', data, function(result) {

		//$("#sub_btn").button("reset");
		if (result.resultCode == "0") {
			$("#errmsg").text("保存成功!");
			$('#my-alert').modal({
				relatedTarget: this,
			});
			//setTimeout('location.href="javascript:history.back();"', 1000);
			setTimeout('location.href="/wx/property/index"', 1000);
		} else {
			$("#errmsg").text(result.datas);
			$('#my-alert').modal({
				relatedTarget: this,
			});
			return;
		}
	});
});
/**
 * [getOwnerInfo description]
 * @return {[type]} [description]
 */
function getOwnerInfo() {



}